package com.clkj.xiuzheng.service.shangcheng;

import com.clkj.xiuzheng.dao.shangcheng.ScBrandMapper;
import com.clkj.xiuzheng.pojo.shangcheng.ProductBrand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@Service
public class ScBrandServiceImpl implements ScBrandService{
    @Autowired
    private ScBrandMapper scBrandMapper;

    @Override
    public void addBrand(ProductBrand productBrand) {
        scBrandMapper.insertSelective(productBrand);
    }

    @Override
    public List<ProductBrand> getBrandList(String brandName, Integer companyId) {
      Example example = new Example(ProductBrand.class);
      Example.Criteria criteria = example.createCriteria();
        if (brandName!=null){
            criteria.andCondition(" brand_name like '%"+brandName+"%'");
        }
        if (companyId!=null){
            criteria.andEqualTo(companyId);
        }
        List<ProductBrand> productBrands = scBrandMapper.selectByExample(example);
        return productBrands;
    }

    @Override
    public void updateBrandStatus(String ids, Integer status) {
        Example example = new Example(ProductBrand.class);
        Example.Criteria criteria = example.createCriteria();
        ProductBrand productBrand = new ProductBrand();
        productBrand.setBrandStatus(status);
        criteria.andIn("brandId",Arrays.asList(ids.split(",")));
        scBrandMapper.updateByExampleSelective(productBrand,example);
    }

    @Override
    public void updateBrandName(Integer brandId, String brandName) {
        ProductBrand productBrand = new ProductBrand();
        productBrand.setBrandId(brandId);
        productBrand.setBrandName(brandName);
        scBrandMapper.updateByPrimaryKeySelective(productBrand);
    }
}
